package newFeature;

import org.junit.Test;
import org.springframework.core.convert.converter.Converter;

import java.util.Comparator;

 class demo1 {
    @Test
    public void test(){

        Comparator<Integer> com1 = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1,o2);
            }
        };

        int compare1 = com1.compare(12,21);
        System.out.println(compare1);

        System.out.println("***********************");
        //Lambda表达式的写法
        Comparator<Integer> com2 = (o1,o2) -> Integer.compare(o1,o2);

        int compare2 = com2.compare(32,21);
        System.out.println(compare2);


        System.out.println("***********************");
        //方法引用
        Comparator<Integer> com3 = Integer :: compare;

        int compare3 = com3.compare(32,21);
        System.out.println(compare3);
    }
}

class demo2 {
    static int outerStaticNum;
    int outerNum;
    public static void main(String[] args) {
        int num = 1;
        Converter<Integer, String> stringConverter =
                from -> String.valueOf(from + num);

        System.out.println(stringConverter.convert(2));
        demo2 test = new demo2();
        test.testScopes();
    }


    void testScopes() {
        Converter<Integer, String> stringConverter1 = (from) -> {
            outerNum = 23;
            return String.valueOf(from+outerNum);
        };
        System.out.println(stringConverter1.convert(2));

        Converter<Integer, String> stringConverter2 = (from) -> {
            outerStaticNum = 72;
            return String.valueOf(from+outerStaticNum);
        };
        System.out.println(stringConverter2.convert(2));
    }

}

public class Lambda{}